package _interview75;

/**
 * 62. 不同路径
 */
public class No62 {
    private int[][] cache;

    public int uniquePaths(int m, int n) {
        cache = new int[m + 1][n + 1];
        for (int i = 0; i < m + 1; i++) {
            for (int j = 0; j < n + 1; j++) {
                cache[i][j] = -1;
            }
        }
        return dfs(m, n);
    }

    private int dfs(int i, int j) {
        if (i < 1 || j < 1) return 0;
        else if (cache[i][j] != -1) return cache[i][j];
        else if (i == 1 && j == 1) return cache[i][j] = 1;
        else return cache[i][j] = dfs(i - 1, j) + dfs(i, j - 1);
    }
}
